package com.ykt.validator;

import com.jfinal.core.Controller;
import com.ykt.common.ValueConstants;

/**
 * @author long.hua
 * @version 1.0.0
 * @since 2016-02-21 22:49
 */
public class OrderValidator  extends BaseValidator {


    @Override
    protected void validate(Controller c) {
        validateRepeatSubmit("token", ValueConstants.PRS_BIZ_ORDER, "tokenMsg", "请不要重复提交！");

        validateInteger("userId",0, Integer.MAX_VALUE, "userIdMsg", "用户ID取值不对！");
        validateRequired("receiptName", "receiptNameMsg", "收货人名不能为空！");
        validateRequired("receiptPhone", "receiptPhoneMsg", "收货电话不能为空！");
        validateInteger("buyType", 0, 1, "shopIdMsg", "购买流程类型取值不对！");
        validateDouble("amount", 0, 1000000, "amountMsg", "订单金额取值不对！");

        if(c.getPara("address") == null && c.getPara("community") == null){
            validateRequired("address", "addressMsg", "收货地址不能为空！");
        }
    }

    @Override
    protected void handleError(Controller c) {
        c.keepPara("userId");
        c.keepPara("receiptName");
        c.keepPara("receiptPhone");
        c.keepPara("shopId");
        c.keepPara("amount");
        c.keepPara("status");
        c.keepPara("address");
        c.keepPara("community");
        c.keepPara("goods");
        c.renderJson(super.toJsonText(c));
    }

}
